var vm = avalon.define({
    $id: "vm-form",
    is_disabled: false,
    form_data: {
        name: name,
        is_effect: is_effect,
        role_access: role_access,
        id: $objAction.getQueryString("id")
    },
    role_list: role_list.role_list,
    check: function check() {
        var self = this;
        if ($checkAction.checkEmpty(self.form_data.name)) {
            layer.msg('请输入权限名称');
            return false;
        } else {
            return true;
        }
    },
    submit: function submit() {
        // 提交更新
        var self = this;
        if (self.check()) {
            var loading = layer.load();
            $handleAjax.handle({
                url: APP_ROOT + "/mapi/index.php?ctl=user_two&act=role_update",
                isTip: false,
                data: self.form_data
            }).done(function(result) {
                layer.close(loading);
                if (result.status == 1) {
                    layer.msg(result.error || '操作成功', {
                        time: 1000
                    });
                    setTimeout(function() {
                        location.href = TMPL_REAL + "/index.php?ctl=user_two&act=role_index";
                    }, 1000);
                } else {
                    layer.msg(result.error || '操作失败');
                }
            }).fail(function(err) {
                console.log(err);
            });
        }
    },
    checkItem(e){
        console.log(e);
        let self = this,
            role_access = document.getElementsByName("role_access");
        if (e.checked) {
            self.form_data.role_access.push(e.value);
        }
        else{
            $objAction.removeByValue(self.form_data.role_access, e.value);
        }
    }
});

$("input[name='role_access']").on('click', function(){
    vm.checkItem(this);
});
